﻿using Microsoft.VisualStudio.TestTools.UnitTesting;

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using TestSysparamterSetting.Base;
using TestUnitTest;
using TestUnitTest.Base;
using TianShu.SysParameterSetting.Service.Abstracts;
using Volo.Abp;
using Volo.Abp.Application.Dtos;
using Xunit;

namespace Test.Service
{
    public class TestSystemParameterSettingService : TestSysparamterSettingTestBase<TestUnitTestModule>
    {
        private readonly ISystemParameterSettingService _systemParameterSettingService;
        public TestSystemParameterSettingService()
        {
            _systemParameterSettingService = GetRequiredService<ISystemParameterSettingService>();
        }

        [Fact]
        public async Task CrudTest()
        {

            await WithUnitOfWorkAsync(CrudExec);



        }

        private async Task CrudExec()
        {

            var systemParameterSetting = GetResult(await _systemParameterSettingService.CreateAsync(new TianShu.SysParameterSetting.Service.Abstracts.Dto.SystemParameterSettingCreateUpdateInput
            {
                Code = "UnitTestDataCode",
                Name = "UnitTestName",
                Value = "true",
                Remark = ""
            }));




            var warehouseTypeUpdate = GetResult(await _systemParameterSettingService.UpdateAsync(systemParameterSetting.Id, new TianShu.SysParameterSetting.Service.Abstracts.Dto.SystemParameterSettingCreateUpdateInput
            {
                Code = systemParameterSetting.Code + "Update",
                Name = systemParameterSetting.Name + "Update",
                Value = "false",
                Remark = ""
            }));

            var systemParameterSettingList = GetResult(await _systemParameterSettingService.GetUrlParamAsync(new List<Volo.Abp.Domain.Shared.UrlParams>()));


            GetResult(await _systemParameterSettingService.DeleteAsync(new List<Guid> { warehouseTypeUpdate.Id }));
        }
        public T GetResult<T>(ResultDto<T> result)
        {
            if (result.Success == false)
            {
                throw new UserFriendlyException(result.ErrorMsg);
            }
            return result.Data;
        }
    }
}
